{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "09504d6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Scatter\n",
    "\n",
    "from pyecharts.faker import Faker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "13d07966",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = [\n",
    "    [10.0, 8.04],\n",
    "    [8.0, 6.95],\n",
    "    [13.0, 7.58],\n",
    "    [9.0, 8.81],\n",
    "    [11.0, 8.33],\n",
    "    [14.0, 9.96],\n",
    "    [6.0, 7.24],\n",
    "    [4.0, 4.26],\n",
    "    [12.0, 10.84],\n",
    "    [7.0, 4.82],\n",
    "    [5.0, 5.68],\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "16945f02",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把data中第一列数据排序\n",
    "data.sort(key=lambda x: x[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a2fea110",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[4.0, 4.26],\n",
       " [5.0, 5.68],\n",
       " [6.0, 7.24],\n",
       " [7.0, 4.82],\n",
       " [8.0, 6.95],\n",
       " [9.0, 8.81],\n",
       " [10.0, 8.04],\n",
       " [11.0, 8.33],\n",
       " [12.0, 10.84],\n",
       " [13.0, 7.58],\n",
       " [14.0, 9.96]]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "63a143c0",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "x_data = [d[0] for d in data]\n",
    "y_data = [d[1] for d in data]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "20058a1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[4.26, 5.68, 7.24, 4.82, 6.95, 8.81, 8.04, 8.33, 10.84, 7.58, 9.96]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(x_data, y_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1b74db63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"ecca0ddfafaa4a499be4f32f4c1bb874\" style=\"width:800px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_ecca0ddfafaa4a499be4f32f4c1bb874 = echarts.init(\n",
       "                    document.getElementById('ecca0ddfafaa4a499be4f32f4c1bb874'), 'white', {renderer: 'canvas'});\n",
       "                var option_ecca0ddfafaa4a499be4f32f4c1bb874 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"symbolSize\": 20,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    4.0,\n",
       "                    4.26\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    5.68\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    7.24\n",
       "                ],\n",
       "                [\n",
       "                    7.0,\n",
       "                    4.82\n",
       "                ],\n",
       "                [\n",
       "                    8.0,\n",
       "                    6.95\n",
       "                ],\n",
       "                [\n",
       "                    9.0,\n",
       "                    8.81\n",
       "                ],\n",
       "                [\n",
       "                    10.0,\n",
       "                    8.04\n",
       "                ],\n",
       "                [\n",
       "                    11.0,\n",
       "                    8.33\n",
       "                ],\n",
       "                [\n",
       "                    12.0,\n",
       "                    10.84\n",
       "                ],\n",
       "                [\n",
       "                    13.0,\n",
       "                    7.58\n",
       "                ],\n",
       "                [\n",
       "                    14.0,\n",
       "                    9.96\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                4.0,\n",
       "                5.0,\n",
       "                6.0,\n",
       "                7.0,\n",
       "                8.0,\n",
       "                9.0,\n",
       "                10.0,\n",
       "                11.0,\n",
       "                12.0,\n",
       "                13.0,\n",
       "                14.0\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_ecca0ddfafaa4a499be4f32f4c1bb874.setOption(option_ecca0ddfafaa4a499be4f32f4c1bb874);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x21bf5d18250>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Scatter(\n",
    "        init_opts=opts.InitOpts(width='800px', height='500px')\n",
    "    )\n",
    "    .add_xaxis(xaxis_data=x_data)\n",
    "    .add_yaxis(\n",
    "        '',\n",
    "        y_axis=y_data,\n",
    "        symbol_size=20,\n",
    "        label_opts=opts.LabelOpts(is_show=True)\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_='value',\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True)\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            type_='value',\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True)\n",
    "        )\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "056c7269",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
